package com.example.qfsx;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;

public class IconAdapter extends RecyclerView.Adapter<IconAdapter.IconViewHolder> {

    private final List<IconItem> iconItems;

    public IconAdapter(List<IconItem> iconItems) {
        this.iconItems = iconItems;
    }

    @NonNull
    @Override
    public IconViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_icon, parent, false);
        return new IconViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull IconViewHolder holder, int position) {
        IconItem item = iconItems.get(position);
        holder.iconImage.setImageResource(item.getIconResId());
        holder.iconText.setText(item.getTitle());
    }

    @Override
    public int getItemCount() {
        return iconItems.size();
    }

    static class IconViewHolder extends RecyclerView.ViewHolder {
        ImageView iconImage;
        TextView iconText;

        public IconViewHolder(@NonNull View itemView) {
            super(itemView);
            iconImage = itemView.findViewById(R.id.icon_image);
            iconText = itemView.findViewById(R.id.icon_text);
        }
    }
}
